package com.rk.jarjuggler.service;

import java.util.Comparator;

public class WorkItemComparator implements Comparator<WorkItem> {
    public int compare(WorkItem workItem1, WorkItem workItem2) {
        int level1 = workItem1.getParent().getLevel();
        int level2 = workItem2.getParent().getLevel();

        int levelCompare = level2 - level1;
//        return levelCompare;

        if (levelCompare != 0){
            return levelCompare;
        }

        String name1 = workItem1.getParent().getName() == null ? "" : workItem1.getParent().getName();
        String name2 = workItem2.getParent().getName() == null ? "" : workItem2.getParent().getName();

        return name1.compareTo(name2);
    }
}
